<?php
/**
 * Amazonfba每日库存报告
 * (amazon-model)
 */
namespace App\Models\Amazon;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class FBAMYIInventory extends Model
{
    protected $connection = 'mysql_amazon';

    protected $table = 'fba_myi_inventory';

    protected $guarded  = [];

    /**
     * FBA在库、在途（单个国家）
     * @param $countryId
     * @param $pSkuId
     * @return mixed
     */
    public static function getInventoryFind($countryId,$pSkuId){
        return self::query()
            ->select(DB::raw('sum(IFNULL(afn_fulfillable_quantity,0)) as instant, sum(IFNULL(afn_inbound_working_quantity,0)) as transit'))
            ->where('country_id',$countryId)
            ->where('psku_id',$pSkuId)
            ->first();
    }

}
